<template>
  <el-container class="container">
    <el-header class="header">
      <el-row :gutter="20">
        <el-col :span="2">
          <div class="grid-content bg-purple">
            <img src="@/assets/CH.png" alt />
          </div>
        </el-col>
        <el-col :span="18">
          <div class="grid-content bg-purple">
            <h3 class="middle">后台管理系统</h3>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple">
            <el-button class="layout" @click="layout">退出</el-button>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px" class="aside">
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          :unique-opened="true"
          :router="true"
        >
          <el-submenu v-for="(item1,index) in menus" :key="index" :index="''+item1.order">
            <template slot="title">
              <i class="el-icon-s-help"></i>
              <span>{{item1.authName}}</span>
            </template>
            <el-menu-item v-for="(item2,index) in item1.children" :key="index" :index="item2.path">
              <i class="el-icon-s-tools"></i>
              {{item2.authName}}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main class="main">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menus: []
    };
  },
  created() {
    this.getMenus();
  },
  methods: {
    async getMenus() {
      const res = await this.$axios.get("menus");
      this.menus = res.data.data;
    },
    layout() {
      this.$router.push({ name: "login" });
      this.$message({
        message: "退出成功",
        type: "success",
        duration: 1000
      });
    }
  }
};
</script>
<style lang="scss">
.container {
  height: 100%;
  .header {
    background-color: #b3c0d1;

    .grid-content {
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 60px;
      }
      .middle {
        text-align: center;
      }
      .layout {
        margin-top: 10px;
      }
    }
  }
  .aside {
    background-color: #d3dce6;
  }
  .main {
    height: 100%;
    background-color: #e9eef3;
  }
}
</style>
